package com.xmhmyh.generalframework.project.sys.service.impl;

import com.xmhmyh.generalframework.common.BaseServiceImpl;
import com.xmhmyh.generalframework.common.constants.Constants;
import com.xmhmyh.generalframework.common.enums.YesOrNo;
import com.xmhmyh.generalframework.common.utils.MyBeanUtils;
import com.xmhmyh.generalframework.framework.yusngen.YuSnGenUtil;
import com.xmhmyh.generalframework.project.sys.entity.Account;
import com.xmhmyh.generalframework.project.sys.entity.User;
import com.xmhmyh.generalframework.project.sys.mapper.AccountMapper;
import com.xmhmyh.generalframework.project.sys.service.IAccountService;
import com.xmhmyh.generalframework.project.sys.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @Author: 于丁
 * @DateTime: 2020/7/24 9:09 上午
 */
@Service
public class AccountServiceImpl extends BaseServiceImpl<AccountMapper, Account> implements IAccountService {
    @Autowired
    private IUserService userService;
    @Autowired
    private YuSnGenUtil yuSnGenUtil;

    @Override
    public Account createStoreAccount(String phone, String name) {
        Account account = new Account();
        MyBeanUtils.setSysInfo(account, Constants.SUPER_USER_ID, Constants.SUPER_ACCOUNT_ID);
        account.setId(uidGenerator.getUID());
        account.setAccountName(name);
        account.setAccountNo(yuSnGenUtil.gen(Account.class).get());
        User user = userService.creatUser(phone, name,account.getId(), Constants.SHOPMANAGE, YesOrNo.YES, YesOrNo.NO);
        account.setAdminUserId(user.getId());
        save(account);
        return account;
    }
}


